package com.skyolder.milkbee.web.rest.my;

import java.net.URISyntaxException;
import java.util.List;

import javax.inject.Inject;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.codahale.metrics.annotation.Timed;
import com.skyolder.milkbee.dto.HisPost;
import com.skyolder.milkbee.service.HisPostService;
import com.skyolder.milkbee.web.rest.util.PaginationUtil;

import io.swagger.annotations.ApiParam;

@RestController
@RequestMapping("/api/my")
public class HisPostResource {
	//private final Logger log = LoggerFactory.getLogger(HisPostResource.class);
	@Inject
	HisPostService hisPostService;
	@GetMapping("/hisposts/{userId}")
	@Timed
	public ResponseEntity<List<HisPost>> getHisPost(@PathVariable Long userId, @ApiParam(required = false) Integer type,
			@ApiParam Pageable pageable) throws URISyntaxException {
		Page<HisPost> page =null;
		if (type == null) {
			type = 1;
		}
		switch (type) {
		case 1: {
			page=hisPostService.findCardsByUserId(userId, pageable);
		}
			break;
		case 2: {
			page=hisPostService.findCommentsByUserId(userId, pageable);
		}
			break;
		default: {
			page=hisPostService.findCardsByUserId(userId, pageable);
		}
		}
		HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/my/hisposts");
		return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
	}
}
